package entity;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * 格式大全:前缀对应以下方法的fmt值
 * <p>
 * 0:Microsoft Word 97 - 2003 文档 (.doc)
 * 1:Microsoft Word 97 - 2003 模板 (.dot)
 * 2:文本文档 (.txt)
 * 3:文本文档 (.txt)
 * 4:文本文档 (.txt)
 * 5:文本文档 (.txt)
 * 6:RTF 格式 (.rtf)
 * 7:文本文档 (.txt)
 * 8:HTML 文档 (.htm)(带文件夹)
 * 9:MHTML 文档 (.mht)(单文件)
 * 10:MHTML 文档 (.mht)(单文件)
 * 11:XML 文档 (.xml)
 * 12:Microsoft Word 文档 (.docx)
 * 13:Microsoft Word 启用宏的文档 (.docm)
 * 14:Microsoft Word 模板 (.dotx)
 * 15:Microsoft Word 启用宏的模板 (.dotm)
 * 16:Microsoft Word 文档 (.docx)
 * 17:PDF 文件 (.pdf)
 * 18:XPS 文档 (.xps)
 * 19:XML 文档 (.xml)
 * 20:XML 文档 (.xml)
 * 21:XML 文档 (.xml)
 * 22:XML 文档 (.xml)
 * 23:OpenDocument 文本 (.odt)
 * 24:WTF 文件 (.wtf)
 *
 * @author yousj
 * @since 2022/4/23
 */
@Getter
@AllArgsConstructor
public enum WordType {

    DOC(0, "doc"),
    DOCT(1, "dot"),
    TXT(2, "txt"),
    RTF(6, "rtf"),
    HTM(8, "htm"),
    MHT(9, "mht"),
    XML(11, "xml"),
    DOCX(12, "docx"),
    DOCM(13, "docm"),
    DOTX(14, "dotx"),
    DOTM(15, "dotm"),
    PDF(17, "pdf"),
    XPS(18, "xps"),
    ODT(23, "odt"),
    WTF(24, "wtf"),;

    private int code;
    private String type;

    public static String getTypeByCode(int code) {
        return Arrays.stream(values()).filter(e -> Objects.equals(code, e.getCode())).findFirst().map(WordType::getType).orElse(null);
    }

}